class Solution
{
public:
    string addStrings(string num1, string num2)
    {
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());

        int n1 = num1.size();
        int n2 = num2.size();
        string result;
        int i = 0;
        bool carry = false;
        while (i < n1 || i < n2)
        {
            int c = 0;
            if (i < n1)
            {
                c += num1[i] - '0';
            }
            if (i < n2)
            {
                c += num2[i] - '0';
            }
            if (carry)
            {
                c += 1;
            }

            if (c > 9)
            {
                c -= 10;
                carry = true;
            }
            else
            {
                carry = false;
            }

            result.push_back(c + '0');
            ++i;
        }
        if (carry)
        {
            result.push_back('1');
        }
        reverse(result.begin(), result.end());
        return result;
    }
};